<?php defined('SYSPATH') or die('No direct script access.');

class Controller_Category extends Controller_Common {

	public $template='layout/index';

	public function action_index() {
		$this->buildCarcas();
		$category = Model::factory('Categories')->get_last_one(1);
		$this->template->title .= ' - Полезное - '.$category->title;

		$this->template->content = View::factory('pages/category', array(
			'catalog' => Model::factory('Categories')->get_main(1),
			'category' => $category,
			'parent_id' => $category->parent_id,
			'decors' => Model::factory('Decors')->get_for_category($this->request->param('id'))
		));
	}

	public function action_one() {
		$this->buildCarcas();
		$category = Model::factory('Categories')->get_one($this->request->param('id'));

		if ($category->type == 0) {
			$catalog = Model::factory('Categories')->get_main(0);
			$this->template->title .= ' - О продукции - '.$category->title;
		} elseif ($category->type == 1) {
			$catalog = Model::factory('Categories')->get_main(1);
			$this->template->title .= ' - Полезное - '.$category->title;
		}

		$this->template->content = View::factory('pages/category', array(
			'catalog' => $catalog,
			'category' => $category,
			'parent_id' => $category->parent_id,
			'decors' => Model::factory('Decors')->get_for_category($this->request->param('id'))
		));
	}

}